from web import models




def send_sms(mobile, sms_code):
    mobile = "+86{}".format(mobile)
    try:

        cred = credential.Credential('AKIDa0B7nhOq3zf5G8l9TMzNVO0MRHrAE3Yn', '4rPincBUYMuCEzUjsdIiuqWv3vYu0qPh')
        client = sms_client.SmsClient(cred, "ap-guangzhou")

        req = models.SendSmsRequest()

        req.SmsSdkAppId = '1400455481'
        req.SignName = "python之路"
        req.TemplateId = '548762'
        req.TemplateParamSet = [sms_code, ]
        req.phoneNumberSet = [mobile, ]
        resp = client.SendSms(req)
        data_object = resp.SendStatusSet[0]
        from tencentcloud.sms.v20210111.models import SendStatus
        if data_object.get("Code") == "OK":
            return True
        return "发送失败"
    except Exception as e:
        pass


# import smtplib
# from email.mime.text import MIMEText
#
# mail_host = 'smtp.163.com'
#
# mail_user = '18292493029'
# mail_pass = 'XUAAWFRQSZXAFWOV'
# sender = '18292493029@163.com'
#
# receivers = ['^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$']
#
# # 邮件内容设置
# message = MIMEText('content', 'plain', 'utf-8')
#
# message['subject'] = '验证码'
#
# message['From'] = sender
#
# message['To'] = receivers[0]
